/*
 * @Author: fishroom
 * @Date: 2023-01-06 15:59:49
 * @LastEditTime: 2023-01-06 17:58:33
 * @FilePath: \koa\app\server\socketServer\socketGroupServer.ts
 */
import socket_group from "../../model/socket_group";

class socketUserServer {
  async getGroupsAll() {
    return await socket_group.findAll();
  }
  async updataGroupById(AGroup: any) {
    let group_id = AGroup.group_id;
    try {
      await socket_group.update(
        {
          ...AGroup,
          member:
            typeof AGroup.member == "string"
              ? AGroup.member
              : JSON.stringify(Object.fromEntries(AGroup.member)),
          group_id: undefined,
        },
        {
          where: {
            group_id,
          },
        }
      );
      return true;
    } catch (error) {
      console.log("更新群出错", error);

      return error;
    }
  }
  async getUserById(group_id: number) {
    try {
      let admin = await socket_group.findOne({
        where: {
          group_id,
        },
      });
      return admin;
    } catch (error) {
      return error;
    }
  }
  async addSocketUser(newGroup: any) {
    try {
      let data = await socket_group.create(newGroup);
      return true;
    } catch (error) {
      return error;
    }
  }
}
export default new socketUserServer();
